home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_c / dbpp20.zip / CLASSES.TXT next >
Text File  |  1994-05-09  |  20KB  |  549 lines

  1. CLASSES.DOC
  2.  
  3.                         DataBase++ ver 2.00 classes
  4.                         ---------------------------
  5.  
  6. This file contains a listing of all classes in DataBase++ along with a
  7. description of all public member functions (methods).
  8.  
  9. TABLE OF CONTENTS
  10. -----------------
  11. 1. DBObject     
  12. 2. DBDatabase 
  13. 3. DBIndexTag 
  14. 4. DBStructure
  15. 5. DBArray    
  16.  
  17.  
  18. 1. DBObject
  19. ------------
  20.  
  21.    No member functions exist. You will not want to or need to create an
  22.    instance of this class.
  23.  
  24. 2. DBDatabase
  25. --------------
  26.  
  27.    This is the core class of DataBase++ and is where most of the action occurs.
  28.    It is responsible for creating, opening and manipulating database files.
  29.    It contains a static data member (class variable) which tracks the number
  30.    of instances of itself.
  31.  
  32.    The first created instance of a DBDatabase object will initialize
  33.    CodeBase by calling it's d4init() function. The last DBDatabase object to
  34.    be deleted will un-initialize CodeBase by calling it's d4init_undo()
  35.    function. This is all done for you; you don't need to do it yourself.
  36.  
  37. --------------------------------------------------------------------------------
  38.    DBDatabase()
  39.  
  40.       Construct a DBDatabase with no arguments. No data file is opened.
  41. --------------------------------------------------------------------------------
  42.    DBDatabase( char * fName )
  43.  
  44.       Construct a DBDatabase using fName as the database file name.
  45.       No data file is opened. 
  46. --------------------------------------------------------------------------------
  47.    BOOL append()
  48.  
  49.       Appends a blank record to the data file. Returns TRUE if successful.
  50. --------------------------------------------------------------------------------
  51.    BOOL appendBlank()
  52.  
  53.       Same as append().
  54. --------------------------------------------------------------------------------
  55.    BOOL bof()
  56.  
  57.       Returns TRUE if file pointer is at beginning of file; otherwise FALSE.
  58. --------------------------------------------------------------------------------
  59.    BOOL close()
  60.  
  61.       The data file is closed. If the file was never opened, nothing takes
  62.       place. Returns TRUE if successful.
  63. --------------------------------------------------------------------------------
  64.    BOOL create( DBStructure& dbs )
  65.  
  66.       Creates a data file from a DBStructure refference. Upon successful
  67.       creation, the data file is opened. Returns TRUE if successful;
  68.       else FALSE.
  69.  
  70.       Example:
  71.  
  72.          DBDatabase db( "test" );
  73.          DBStructure dbs;                     
  74.          dbs.addField( "NAME", 'C', 20 );       // Add fields.
  75.          dbs.addField( "AGE", 'N', 3 );
  76.          db.create( dbs );
  77. --------------------------------------------------------------------------------
  78.    BOOL create( DBStructure& dbs, DBIndexTag& idx )
  79.  
  80.       Creates a data file from a DBStructure refference and creates index
  81.       files as well. Upon successful creation, the data file and index files
  82.       are opened. Returns TRUE if successful; else FALSE.
  83.  
  84.       Example:
  85.  
  86.          DBDatabase db( "test" );
  87.          DBStructure dbs;
  88.          DBIndexTag tag;
  89.           
  90.          dbs.addField( "NAME", 'C', 20 );       // Add fields.
  91.          dbs.addField( "AGE", 'N', 3 );
  92.  
  93.          tag.addTag( "TEST", "NAME" );          // Add tag definitions.
  94.  
  95.          db.create( dbs, tag );
  96. --------------------------------------------------------------------------------
  97.    BOOL createIndex( DBIndexTag& idx )
  98.  
  99.       An index file is created and opened for the given database from a
  100.       DBIndexTag refference. Returns TRUE if successful; else FALSE.
  101.  
  102.       Example:
  103.  
  104.          DBDatabase db( "test" );
  105.          DBIndexTag tag;
  106.  
  107.          tag.addTag( "TEST", "NAME" );          // Add tag definitions.
  108.  
  109.          db.open();
  110.          db.createIndex( tag );
  111. --------------------------------------------------------------------------------
  112.    void deleteRec()
  113.  
  114.       The record at the current record pointer is marked for deletion.
  115.       The record is not actually removed until pack() is called. The record
  116.       pointer remains on the record that is deleted.
  117. --------------------------------------------------------------------------------
  118.    BOOL deleted()
  119.  
  120.       Returns TRUE if the current record is marked for deletion; else FALSE.
  121. --------------------------------------------------------------------------------
  122.    BOOL eof()
  123.  
  124.       Returns TRUE if the record pointer is at end of file; else FALSE.
  125. --------------------------------------------------------------------------------
  126.    int fieldNum( char *fldName )
  127.  
  128.       Returns the number of the field that matches fldName. If fldName is
  129.       not a valid field in the data file, CodeBase will generate an error.
  130. --------------------------------------------------------------------------------
  131.    int fieldType( char *fldName )
  132.  
  133.       Returns one of the following:
  134.  
  135.          'C'  - Character type
  136.          'N'  - Numeric type
  137.          'D'  - Date type
  138.          'L'  - Logical type
  139.          'M'  - Memo type.
  140.          'U'  - Undefined type.
  141. --------------------------------------------------------------------------------
  142.    BOOL fileLock()
  143.  
  144.       The data file is locked. Returns TRUE if successful; else FALSE.
  145. --------------------------------------------------------------------------------
  146.    char * fileName()
  147.  
  148.       Returns the name of the file associated with the data file.
  149. --------------------------------------------------------------------------------
  150.    D4DATA * getD4DATA()
  151.  
  152.       Returns a pointer to CodeBase's D4DATA struct for the associated data
  153.       file. This pointer is NULL if no data file has been opened.
  154. --------------------------------------------------------------------------------
  155.    char * getDate( char *fldName )
  156.  
  157.       Returns the contents of a date field, fldName, as a string in the form of
  158.       "MM/DD/YYYY\n". The string is stored in a CodeBase internal buffer and
  159.       should be used immedialtely or copied to a local buffer.
  160. --------------------------------------------------------------------------------
  161.    double getDouble( char *fldName )
  162.  
  163.       Returns a "numeric" field, fldName, as a double.
  164. --------------------------------------------------------------------------------
  165.    int getInt( char *fldName )
  166.  
  167.       Returns a "numeric" field, fldName, as an int.
  168. --------------------------------------------------------------------------------
  169.    int getLogical( char *fldName )
  170.    
  171.       Returns a "logical" field, fldName, as an int.
  172. --------------------------------------------------------------------------------
  173.    long getLong( char *fldName )
  174.    
  175.       Returns a "numeric" field, fldName, as an long.
  176. --------------------------------------------------------------------------------
  177.    char * getMemo( char *fldName )
  178.  
  179.       Returns the contents of the memo field, fldName, as a string. 
  180.       The string is stored in a CodeBase internal buffer and should be used
  181.       immedialtely or copied to a local buffer.
  182. --------------------------------------------------------------------------------
  183.    char * getString( char *fldName )
  184.    
  185.       Returns the contents of field, fldName, as a string. 
  186.       The string is stored in a CodeBase internal buffer and should be used
  187.       immedialtely or copied to a local buffer.
  188. --------------------------------------------------------------------------------
  189.    void go( long nRecno )
  190.  
  191.       Move record pointer to nRecno.
  192. --------------------------------------------------------------------------------
  193.    void goBottom();
  194.  
  195.       Move record pointer to last record in file.
  196. --------------------------------------------------------------------------------
  197.    void goTop();
  198.  
  199.       Move record pointer to first record in file.
  200. --------------------------------------------------------------------------------
  201.    char * indexTag()
  202.  
  203.       Return a pointer to the currently selected index tag name.
  204.  
  205.       Example:
  206.  
  207.          db.setIndexTag( "PRIMARY" );
  208.          db.indexTag();                // Returns "PRIMARY".
  209. --------------------------------------------------------------------------------
  210.    BOOL isOpen()
  211.  
  212.       Returns TRUE if file is open, else FALSE.
  213. --------------------------------------------------------------------------------
  214.    void memoPack()
  215.  
  216.       Packs the memo file.
  217. --------------------------------------------------------------------------------
  218.    int numFields()
  219.  
  220.       Returns the number of fields in the database.
  221. --------------------------------------------------------------------------------
  222.    BOOL open();
  223.  
  224.       Opens the database file associated with the DBDatabase object.
  225.       Returns TRUE if successful, else FALSE. If the file is already open,
  226.       open() simply returns TRUE.
  227. --------------------------------------------------------------------------------
  228.    BOOL openIndex( char * indexFile )
  229.  
  230.       Opens an index file. This method only applies when using Clipper or
  231.       dBASE index files and DBF_GROUPS is not defined. Returns TRUE if
  232.       index file opened successfully.
  233. --------------------------------------------------------------------------------
  234.    void pack( int mPack = 0 )
  235.  
  236.       Packs the database, removing all records marked for deletion.
  237.       If mPack is TRUE (non 0), memoPack() is called as well.
  238. --------------------------------------------------------------------------------
  239.    long reccount()
  240.  
  241.       Returns the number of records in the database. 
  242. --------------------------------------------------------------------------------
  243.    void recall()
  244.  
  245.       Recalls a deleted record.
  246. --------------------------------------------------------------------------------
  247.    void reindex()
  248.  
  249.       Reindexes all index files associated with the database.
  250. --------------------------------------------------------------------------------
  251.    BOOL recLock()
  252.  
  253.       Locks a record. Returns TRUE if lock was successful, else FALSE.
  254.       NOTE: You must call DBDatabase::SetMultiUser( TRUE ) to use network
  255.             functions.
  256. --------------------------------------------------------------------------------
  257.    long recno()
  258.  
  259.       Returns the current record number.
  260. --------------------------------------------------------------------------------
  261.    void replace( char *fldName, char *str )
  262.  
  263.       Replaces the field fldName with the string pointed to by str.
  264. --------------------------------------------------------------------------------
  265.    void replace( char *fldName, double d )
  266.  
  267.       Replaces the field fldName with the double value d.
  268. --------------------------------------------------------------------------------
  269.    void replace( char *fldName, int i )
  270.  
  271.       Replaces the field fldName with the integer value i.
  272. --------------------------------------------------------------------------------
  273.    void replace( char *fldName, long l )
  274.  
  275.       Replaces the field fldName with the long value l.
  276. --------------------------------------------------------------------------------
  277.    BOOL seek( char *seekExpr )
  278.  
  279.       Seeks the expression string pointed to by seekExpr using the current
  280.       index tag. Returns TRUE if found, else FALSE.
  281.  
  282.       Example:
  283.  
  284.          db.setIndexTag( "NAMES" );
  285.          if ( db.seek( "JEFF" ) )
  286.             cout << "Found!" << endl;
  287. --------------------------------------------------------------------------------
  288.    void setFileName( char * fName )
  289.  
  290.       Sets the file name of the DBDatabase object to fName. This has no effect
  291.       on an open database. It allows you to create a DBDatabase with no file
  292.       name and assign one at a later time.
  293.  
  294.       Example:
  295.  
  296.          DBDatabase db;
  297.          db.setFileName( "test" );
  298.          db.open();
  299. --------------------------------------------------------------------------------
  300.    void setFilter( FilterFunc ff )
  301.  
  302.       Assigns the address of a user defined function which returns TRUE if
  303.       the filter condition is met. FilterFunc is a typedef for a function
  304.       pointer in the form of:
  305.  
  306.          typedef BOOL ( * FilterFunc )( DBDatabase & db );
  307.  
  308.       All methods which result in the movement of the record pointer check to
  309.       see if a filter function is set. If a filter function is provided, it
  310.       is executed and if it returns FALSE, the record pointer is moved off
  311.       the filtered record in the appropriate direction.
  312.  
  313.       Example which filters out all deleted records:
  314.  
  315.          // Your filter function
  316.          BOOL MyFilter( DBDatabase &dbf ) {
  317.             return( ! dbf.deleted() );
  318.          }
  319.  
  320.          // Set the filter function address.
  321.          db.setFilter( MyFilter );
  322.  
  323.          // Display all records that are not deleted.
  324.          for ( db.goTop(); ! db.eof(); db.skip() )
  325.             cout << db.getString( "name" ) << endl;
  326. --------------------------------------------------------------------------------
  327.    BOOL setIndexTag( char *aTagName = NULL )
  328.  
  329.       Sets the current index tag to aTagName. If aTagName == NULL,
  330.       record order sorting is set.
  331.  
  332.       Example:
  333.  
  334.          db.setIndexTag( "PRIMARY" );  // Sets primary index tag.
  335.          db.setIndexTag();             // Sets record order.
  336. --------------------------------------------------------------------------------
  337.    void skip( int nRecs = 1 )
  338.  
  339.       Skips nRecs records in the database. nRecs defaults to 1.
  340. --------------------------------------------------------------------------------
  341.    void unlock()
  342.  
  343.       Removes all locks imposed on the file.
  344. --------------------------------------------------------------------------------
  345.    int unlockIndex()
  346.  
  347.       Unlocks the index files associated with the database. This is required
  348.       by CodeBase if you are using CodeBase in multi user mode. It is
  349.       required to be called after the movement of the record pointer for
  350.       proper operation. You should never need to call unlockIndex() directly.
  351. --------------------------------------------------------------------------------
  352.    void zap( int mPack = 0 )
  353.  
  354.       Removes all records in the database. If mPack is TRUE, memoPack() is
  355.       called. USE WITH CARE, all records will be removed.
  356. --------------------------------------------------------------------------------
  357.    static C4CODE * CodeBase()
  358.  
  359.       Returns a pointer to the C4CODE structure used by CodeBase.
  360. --------------------------------------------------------------------------------
  361.    static char * GetCentury()
  362.  
  363.       Returns a pointer to a string which represents the current century
  364.       used for date conversions.
  365. --------------------------------------------------------------------------------
  366.    static int Instances()
  367.  
  368.       Returns the number of instances of a DBDatabase object. 
  369. --------------------------------------------------------------------------------
  370.    static int OpenFiles()
  371.  
  372.       Returns the number of open database files.
  373. --------------------------------------------------------------------------------
  374.    static void SetCentury( char *aCentury )
  375.  
  376.       Sets the century string used in date conversions to aCentury.
  377. --------------------------------------------------------------------------------
  378.    static void SetMultiUser( BOOL state )
  379.  
  380.       Sets the multi user state on or off. By default, multi user state is
  381.       disabled. If state is TRUE, multi user mode is enabled and record
  382.       and file locking techniques should be used.
  383. --------------------------------------------------------------------------------
  384.    static void CloseAll()
  385.  
  386.       Closes all open data files in all DBDatabase object instances.
  387. --------------------------------------------------------------------------------
  388.  
  389. 3. DBIndexTag 
  390. --------------
  391.  
  392.    DBIndexTag is responsible for constructing and manipulating collections
  393.    of index tag definitions. You use it to specify a new index definition.
  394.    Once a DBIndexTag object is filled with your tag descriptions, you
  395.    can create indexes with it by calling DBDatabase::create() or
  396.    DBDatabase::createIndexTag().
  397.  
  398.    It's most notable method is addTag(), which adds a tag description.
  399.    addTag() takes the following form:
  400.  
  401.    void addTag( char *tagName, char *expression, int unique = 0, int descending = 0 );  
  402.  
  403.    Example:
  404.  
  405.       DBDatabase db( "test" );
  406.       DBIndexTag dbTag;
  407.  
  408.       // Create a new tag definition called "NAMES" whose key is
  409.       // "UPPER( LASTNAME )"...
  410.       dbTag.addTag( "NAMES", "UPPER( LASTNAME )" );
  411.  
  412.       // Open file.
  413.       db.open();
  414.  
  415.       // Create index tags.
  416.       db.createIndex( dbTag );
  417.  
  418.  
  419. 4. DBStructure
  420. ---------------
  421.  
  422.    DBStructure is responsible for constructing and manipulating collections
  423.    of dataase field definitions. You use it to specify a new field definition.
  424.    Once a DBStructure object is filled with your field descriptions, you
  425.    can create database files with it by calling DBDatabase::create().
  426.  
  427.    It's most notable method is addField(), which adds a field description.
  428.    addField() takes the following form:
  429.  
  430.    void addField( char *fldName, char type, int len, int dec = 0 );
  431.  
  432.    Example:
  433.  
  434.       DBDatabase db( "test" );
  435.       DBStructure dbs;
  436.  
  437.       // Create some fields.
  438.       dbs.addField( "NAME", 'C', 30 );
  439.       dbs.addField( "AGE", 'N', 3 );
  440.       dbs.addField( "BIRTHDATE", 'D', 8 );
  441.       dbs.addField( "SALARY", 'N', 8, 2 );
  442.       dbs.addField( "NOTES", 'M', 10 );
  443.  
  444.       // Create file.
  445.       db.create( dbs );
  446.  
  447.  
  448. 5. DBArray
  449. -----------
  450.  
  451.    DBArray is an array class which stores pointers to DBObject types and
  452.    it's descendents. It is used in the DBDatabase, DBIndexTag and
  453.    DBStructure classes.
  454.  
  455.    Member functions:
  456.    
  457. --------------------------------------------------------------------------------
  458.       DBArray( int sz = 1, int growBy = 1 )
  459.  
  460.          Construct a DBArray. sz controls the initial maximum number of
  461.          DBObject pointers that will fit in the array. growBy controls the
  462.          number of DBObject pointers that the array will expand by if the
  463.          sz limit is exceeded.
  464. --------------------------------------------------------------------------------
  465.       void add( DBObject *anObject )
  466.  
  467.          Adds a pointer to a DBObject pointer pointed to by anObject.
  468. --------------------------------------------------------------------------------
  469.       int itemsInArray()
  470.  
  471.          Returns the number of items in the array.
  472. --------------------------------------------------------------------------------
  473.       void ownsObjects( unsigned bool )
  474.  
  475.          Sets the ownership status of the object pointers in the array. If
  476.          bool == TRUE (the default), the objects contained in the array will
  477.          be destroyed by the array when the array goes out of scope. If
  478.          bool == FALSE, the objects will not be deleted.
  479. --------------------------------------------------------------------------------
  480.       void remove( int index )
  481.  
  482.          Removes an object pointer at index. If index is out of range, nothing
  483.          happens. If the array owns the objects, the object is deleted.
  484. --------------------------------------------------------------------------------
  485.       void remove( DBObject *anObject )
  486.  
  487.          Removes an object pointer whose address matches anObject.
  488.          If the array owns the objects, the object is deleted.
  489. --------------------------------------------------------------------------------
  490.       DBObject * operator [] ( int index )
  491.  
  492.          Returns the object pointer at index.
  493. --------------------------------------------------------------------------------
  494.       
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.    
  549.